package com.sf.fy.uav.applet.user.controller;

import com.sf.fy.uav.common.awt.JwtUtil;
import com.sf.fy.uav.common.request.user.ReceivingInformationRequest;
import com.sf.fy.uav.common.response.user.ReceivingInformationResponse;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.user.entity.ReceivingInformation;
import com.sf.fy.uav.user.rest.ReceivingInformationRest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LTQ
 */
@RestController
@RequestMapping("/sys/receiving-information/")
public class ReceivingInformationController {


    @Autowired
    private ReceivingInformationRest receivingInformationRest;

    @PostMapping("add")
    public Rs<Void> add(@RequestBody ReceivingInformationRequest receivingInformationRequest) {
        receivingInformationRest.add(receivingInformationRequest);
        return Rs.success();
    }

    /**
     * 获取最近n条
     */
    @GetMapping("get-last-ten")
    public Rs<List<ReceivingInformationResponse>> getLastTen(@RequestParam Integer num) {
        String userId = JwtUtil.getUserId();
        return Rs.success(receivingInformationRest.getLastTen(userId, num));
    }

    @GetMapping("delete")
    public Rs<Void> delete(@RequestParam String id) {
        receivingInformationRest.deleteRescue(id);
        return Rs.success();
    }
    @GetMapping("getPhoneNum")
    public Rs<ReceivingInformation> getPhoneNum(@RequestParam String id) {
        return Rs.success(receivingInformationRest.getPhoneNum(id));
    }
    @PostMapping("edit")
    public Rs<Void> editAddress(@RequestBody ReceivingInformationRequest receivingInformationRequest){
        receivingInformationRest.editAddressRescue(receivingInformationRequest);
        return Rs.success();
    }

}